<!DOCTYPE HTML>
<html>

<head>
	<link rel="bookmark"  type="image/x-icon"  href="/img/logo_miccall.png"/>
	<link rel="shortcut icon" href="/img/logo_miccall.png">
	
			    <title>
    Ame雨
    </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    <link rel="stylesheet" href="/amelin-ting/css/mic_main.css" />
    <link rel="stylesheet" href="/amelin-ting/css/dropdownMenu.css" />
    <meta name="keywords" content="Ame雨" />
    
    	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
	 
    <noscript>
        <link rel="stylesheet" href="/amelin-ting/css/noscript.css" />
    </noscript>
    <style type="text/css">
        body:before {
          content: ' ';
          position: fixed;
          top: 0;
          background: url('/amelin-ting/img/bg.jpg') center 0 no-repeat;
          right: 0;
          bottom: 0;
          left: 0;
          background-size: cover; 
        }
    </style>

			    
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script async type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


    <script src="/amelin-ting/js/jquery.min.js"></script>
    <script src="/amelin-ting/js/jquery.scrollex.min.js"></script>
    <script src="/amelin-ting/js/jquery.scrolly.min.js"></script>
    <script src="/amelin-ting/js/skel.min.js"></script>
    <script src="/amelin-ting/js/util.js"></script>
    <script src="/amelin-ting/js/main.js"></script>
	
<meta name="generator" content="Hexo 5.4.0"></head>
    
		
<!-- Layouts -->



<!--  代码渲染  -->
<link rel="stylesheet" href="/css/prism_coy.css" />
<link rel="stylesheet" href="/css/typo.css" />
<!-- 文章页 -->
<body class="is-loading">
    <!-- Wrapper 外包 s-->
    <div id="wrapper" class="fade-in">
        <!-- Intro 头部显示 s -->
        <!-- Intro 头部显示 e -->
        <!-- Header 头部logo start -->
        <header id="header">
    <a href="/amelin-ting/" class="logo">Art Space</a>
</header>
        <!-- Nav 导航条 start -->
        <nav id="nav" class="special" >
            <ul class="menu links" >
			<!-- Homepage  主页  --> 
			<li >
	            <a href="/amelin-ting/" rel="nofollow">主页</a>
	        </li>
			<!-- categories_name  分类   --> 
	        
	        <li class="active">
	            <a href="#s1">分类</a>
	                    <ul class="submenu">
	                        <li>
	                        <a class="category-link" href="/amelin-ting/categories/Go/">Go</a></li><li><a class="category-link" href="/amelin-ting/categories/django/">django</a></li><li><a class="category-link" href="/amelin-ting/categories/drf/">drf</a></li><li><a class="category-link" href="/amelin-ting/categories/gin/">gin</a></li><li><a class="category-link" href="/amelin-ting/categories/go/">go</a></li><li><a class="category-link" href="/amelin-ting/categories/linux/">linux</a></li><li><a class="category-link" href="/amelin-ting/categories/mysql/">mysql</a></li><li><a class="category-link" href="/amelin-ting/categories/python/">python</a></li><li><a class="category-link" href="/amelin-ting/categories/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/">内网穿透</a></li><li><a class="category-link" href="/amelin-ting/categories/%E5%89%8D%E7%AB%AF/">前端</a>
	                    </ul>
	        </li>
	        
	        <!-- archives  归档   --> 
	        
	        
		        <!-- Pages 自定义   -->
		        
		        <li>
		            <a href="/about/" title="简历">
		                简历
		            </a>
		        </li>
		        
		        <li>
		            <a href="/group/" title="团队">
		                团队
		            </a>
		        </li>
		        
		        <li>
		            <a href="/gallery/" title="图库">
		                图库
		            </a>
		        </li>
		        
		        <li>
		            <a href="/tag/" title="标签">
		                标签
		            </a>
		        </li>
		        


            </ul>
            <!-- icons 图标   -->
			<ul class="icons">
                    
                    <li>
                        <a title="github" href="https://github.com/miccall" target="_blank" rel="noopener">
                            <i class="icon fa fa-github"></i>
                        </a>
                    </li>
                    
                    <li>
                        <a title="500px" href="http://500px.com" target="_blank" rel="noopener">
                            <i class="icon fa fa-500px"></i>
                        </a>
                    </li>
                    
			</ul>
</nav>

        <div id="main" >
            <div class ="post_page_title_img" style="height: 25rem;background-image: url(https://img2.baidu.com/it/u=1883465625,2712220823&amp;fm=26&amp;fmt=auto);background-position: center; background-repeat:no-repeat; background-size:cover;-moz-background-size:cover;overflow:hidden;" >
                <a href="#" style="padding: 4rem 4rem 2rem 4rem ;"><h2 >django视图层</h2></a>
            </div>
            <!-- Post -->
            <div class="typo" style="padding: 3rem;">
                <h2 id="一、三板斧介绍"><a href="#一、三板斧介绍" class="headerlink" title="一、三板斧介绍"></a>一、三板斧介绍</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">HttpResponse</span></span><br><span class="line"><span class="string">	返回字符串类型的数据</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">render</span></span><br><span class="line"><span class="string">	返回html文件的   并且在返回给浏览器之前还可以给html文件传值</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">redirect</span></span><br><span class="line"><span class="string">	重定向</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="comment"># 视图函数必须要返回一个HttpResponse对象  正确   研究三者的源码即可得处结论</span></span><br><span class="line">The view app01.views.index didn<span class="string">&#x27;t return an HttpResponse object. It returned None instead.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># render简单内部原理</span></span><br><span class="line"><span class="string">	from django.template import Template,Context</span></span><br><span class="line"><span class="string">    res = Template(&#x27;</span>&lt;h1&gt;&#123;&#123; user &#125;&#125;&lt;/h1&gt;<span class="string">&#x27;)</span></span><br><span class="line"><span class="string">    con = Context(&#123;&#x27;</span>use<span class="string">r&#x27;:&#123;&#x27;</span>username<span class="string">&#x27;:&#x27;</span>jason<span class="string">&#x27;,&#x27;</span>password<span class="string">&#x27;:123&#125;&#125;)</span></span><br><span class="line"><span class="string">    ret = res.render(con)</span></span><br><span class="line"><span class="string">    print(ret)</span></span><br><span class="line"><span class="string">    return HttpResponse(ret)</span></span><br></pre></td></tr></table></figure>

<h2 id="二、JsonResponse对象"><a href="#二、JsonResponse对象" class="headerlink" title="二、JsonResponse对象"></a>二、JsonResponse对象</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">json格式的数据有什么用？</span></span><br><span class="line"><span class="string">	前后端数据交互需要使用到json作为过渡 实现跨语言传输数据</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">前端序列化</span></span><br><span class="line"><span class="string">	JSON.stringify()					json.dumps()</span></span><br><span class="line"><span class="string">	JSON.parse()							json.loads()</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="number">1.</span> 代码演示</span><br><span class="line">    <span class="keyword">import</span> json</span><br><span class="line">    <span class="keyword">from</span> django.http <span class="keyword">import</span> JsonResponse</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">ab_json</span>(<span class="params">request</span>):</span></span><br><span class="line">        user_dict = &#123;<span class="string">&#x27;username&#x27;</span>:<span class="string">&#x27;jason好帅哦,我好喜欢!&#x27;</span>,<span class="string">&#x27;password&#x27;</span>:<span class="string">&#x27;123&#x27;</span>,<span class="string">&#x27;hobby&#x27;</span>:<span class="string">&#x27;girl&#x27;</span>&#125;</span><br><span class="line">        l = [<span class="number">111</span>,<span class="number">222</span>,<span class="number">333</span>,<span class="number">444</span>,<span class="number">555</span>]</span><br><span class="line">        <span class="comment"># 先转成json格式字符串</span></span><br><span class="line">        <span class="comment"># json_str = json.dumps(user_dict,ensure_ascii=False)</span></span><br><span class="line">        <span class="comment"># 将该字符串返回</span></span><br><span class="line">        <span class="comment"># return HttpResponse(json_str)</span></span><br><span class="line">        读源码掌握用法</span><br><span class="line">        <span class="keyword">return</span> JsonResponse(user_dict,json_dumps_params=&#123;<span class="string">&#x27;ensure_ascii&#x27;</span>:<span class="literal">False</span>&#125;)</span><br><span class="line">   	    <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">   	    序列化列表报错：In order to allow non-dict objects to be serialized set the safe parameter to False.</span></span><br><span class="line"><span class="string">        return JsonResponse(l,safe=False)  </span></span><br><span class="line"><span class="string">        默认只能序列化字典 序列化其他需要加safe参数	</span></span><br><span class="line"><span class="string">   	    &quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>

<h2 id="三、上传文件"><a href="#三、上传文件" class="headerlink" title="三、上传文件"></a>三、上传文件</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> form上传文件需要注意的事项</span><br><span class="line">    <span class="number">1.1</span> method必须指定成post</span><br><span class="line">    <span class="number">1.2</span> enctype必须换成formdata</span><br><span class="line">    </span><br><span class="line"><span class="number">2.</span> 代码演示</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">ab_file</span>(<span class="params">request</span>):</span></span><br><span class="line">        <span class="keyword">if</span> request.method == <span class="string">&#x27;POST&#x27;</span>:</span><br><span class="line">            <span class="comment"># print(request.POST)  # 只能获取普通的简直对数据 文件不行</span></span><br><span class="line">            <span class="built_in">print</span>(request.FILES)  <span class="comment"># 获取文件数据</span></span><br><span class="line">            <span class="comment"># &lt;MultiValueDict: &#123;&#x27;file&#x27;:[&lt;InMemoryUploadedFile:u=1288812541,1979816195&amp;fm=26&amp;gp=0.jpg(image/jpeg)&gt;]&#125;&gt;</span></span><br><span class="line">            file_obj = request.FILES.get(<span class="string">&#x27;file&#x27;</span>)  <span class="comment"># 文件对象</span></span><br><span class="line">            <span class="built_in">print</span>(file_obj.name)</span><br><span class="line">            <span class="keyword">with</span> <span class="built_in">open</span>(file_obj.name,<span class="string">&#x27;wb&#x27;</span>) <span class="keyword">as</span> f:</span><br><span class="line">                <span class="keyword">for</span> line <span class="keyword">in</span> file_obj.chunks():  <span class="comment"># 推荐加上chunks方法 其实跟不加是一样的都是一行行的读取</span></span><br><span class="line">                    f.write(line)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> render(request,<span class="string">&#x27;form.html&#x27;</span>)</span><br></pre></td></tr></table></figure>

<h2 id="四、request对象方法补充"><a href="#四、request对象方法补充" class="headerlink" title="四、request对象方法补充"></a>四、request对象方法补充</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">request.method</span></span><br><span class="line"><span class="string">request.POST</span></span><br><span class="line"><span class="string">request.GET</span></span><br><span class="line"><span class="string">request.FILES</span></span><br><span class="line"><span class="string">request.body  # 原生的浏览器发过来的二进制数据  后面详细的讲</span></span><br><span class="line"><span class="string">request.path </span></span><br><span class="line"><span class="string">request.path_info</span></span><br><span class="line"><span class="string">request.get_full_path()  能过获取完整的url及问号后面的参数 </span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line">    <span class="built_in">print</span>(request.path)  <span class="comment"># /app01/ab_file/</span></span><br><span class="line">    <span class="built_in">print</span>(request.path_info)  <span class="comment"># /app01/ab_file/</span></span><br><span class="line">    <span class="built_in">print</span>(request.get_full_path())  <span class="comment"># /app01/ab_file/?username=jason</span></span><br></pre></td></tr></table></figure>

<h2 id="五、FBV-amp-CBV"><a href="#五、FBV-amp-CBV" class="headerlink" title="五、FBV&amp;CBV"></a>五、FBV&amp;CBV</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>视图函数既可以是函数也可以是类</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> FBV</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">index</span>(<span class="params">request</span>):</span></span><br><span class="line">      <span class="keyword">return</span> HttpResponse(<span class="string">&#x27;index&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> CBV</span><br><span class="line">    <span class="comment"># CBV路由</span></span><br><span class="line">    url(<span class="string">r&#x27;^login/&#x27;</span>,views.MyLogin.as_view())</span><br><span class="line">    </span><br><span class="line">	<span class="keyword">from</span> django.views <span class="keyword">import</span> View</span><br><span class="line">	<span class="class"><span class="keyword">class</span> <span class="title">MyLogin</span>(<span class="params">View</span>):</span></span><br><span class="line">    	<span class="function"><span class="keyword">def</span> <span class="title">get</span>(<span class="params">self,request</span>):</span></span><br><span class="line">        	<span class="keyword">return</span> render(request,<span class="string">&#x27;form.html&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    	<span class="function"><span class="keyword">def</span> <span class="title">post</span>(<span class="params">self,request</span>):</span></span><br><span class="line">        	<span class="keyword">return</span> HttpResponse(<span class="string">&#x27;post方法&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">      </span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">FBV和CBV各有千秋</span></span><br><span class="line"><span class="string">CBV特点</span></span><br><span class="line"><span class="string">	能够直接根据请求方式的不同直接匹配到对应的方法执行</span></span><br><span class="line"><span class="string">	</span></span><br><span class="line"><span class="string">	内部到底是怎么实现的？</span></span><br><span class="line"><span class="string">		CBV内部源码(******)</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>

<h2 id="六、CBV源码解析"><a href="#六、CBV源码解析" class="headerlink" title="六、CBV源码解析"></a>六、CBV源码解析</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;自己不要修改源码 除了bug很难找&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 突破口在urls.py</span></span><br><span class="line">url(<span class="string">r&#x27;^login/&#x27;</span>,views.MyLogin.as_view())</span><br><span class="line"><span class="comment"># url(r&#x27;^login/&#x27;,views.view)  FBV一模一样</span></span><br><span class="line"><span class="comment"># CBV与FBV在路由匹配上本质是一样的 都是路由 对应 函数内存地址</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">函数名/方法名 加括号执行优先级最高</span></span><br><span class="line"><span class="string">猜测</span></span><br><span class="line"><span class="string">    as_view()</span></span><br><span class="line"><span class="string">        要么是被@staicmethod修饰的静态方法</span></span><br><span class="line"><span class="string">        要么是被@classmethod修饰的类方法  正确</span></span><br><span class="line"><span class="string">        </span></span><br><span class="line"><span class="string">    @classonlymethod</span></span><br><span class="line"><span class="string">    def as_view(cls, **initkwargs):</span></span><br><span class="line"><span class="string">        pass</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="meta">    @classonlymethod</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">as_view</span>(<span class="params">cls, **initkwargs</span>):</span></span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        cls就是我们自己写的类   MyCBV</span></span><br><span class="line"><span class="string">        Main entry point for a request-response process.</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">view</span>(<span class="params">request, *args, **kwargs</span>):</span></span><br><span class="line">            self = cls(**initkwargs)  <span class="comment"># cls是我们自己写的类</span></span><br><span class="line">            <span class="comment"># self = MyLogin(**initkwargs)  产生一个我们自己写的类的对象</span></span><br><span class="line">            <span class="keyword">return</span> self.dispatch(request, *args, **kwargs)</span><br><span class="line">            <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">            以后你们会经常需要看源码 但是在看python源码的时候 一定要时刻提醒自己面向对象属性方法查找顺序</span></span><br><span class="line"><span class="string">                先从对象自己找</span></span><br><span class="line"><span class="string">                再去产生对象的类里面找</span></span><br><span class="line"><span class="string">                之后再去父类找</span></span><br><span class="line"><span class="string">                ...</span></span><br><span class="line"><span class="string">            总结:看源码只要看到了self点一个东西 一定要问你自己当前这个self到底是谁</span></span><br><span class="line"><span class="string">            &quot;&quot;&quot;</span></span><br><span class="line">        <span class="keyword">return</span> view</span><br><span class="line">      </span><br><span class="line">		<span class="comment"># CBV的精髓</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">dispatch</span>(<span class="params">self, request, *args, **kwargs</span>):</span></span><br><span class="line">        <span class="comment"># 获取当前请求的小写格式 然后比对当前请求方式是否合法</span></span><br><span class="line">        <span class="comment"># get请求为例</span></span><br><span class="line">        <span class="comment"># post请求</span></span><br><span class="line">        <span class="keyword">if</span> request.method.lower() <span class="keyword">in</span> self.http_method_names:</span><br><span class="line">            handler = <span class="built_in">getattr</span>(self, request.method.lower(), self.http_method_not_allowed)</span><br><span class="line">            <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">            反射:通过字符串来操作对象的属性或者方法</span></span><br><span class="line"><span class="string">                handler = getattr(自己写的类产生的对象,&#x27;get&#x27;,当找不到get属性或者方法的时候就会用第三个参数)</span></span><br><span class="line"><span class="string">                handler = 我们自己写的类里面的get方法</span></span><br><span class="line"><span class="string">            &quot;&quot;&quot;</span></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            handler = self.http_method_not_allowed</span><br><span class="line">        <span class="keyword">return</span> handler(request, *args, **kwargs)</span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        自动调用get方法</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 要求掌握到不看源码也能够描述出CBV的内部执行流程(******)</span></span><br></pre></td></tr></table></figure>




            </div>

            <!-- Post Comments -->
            
    <!-- 使用 DISQUS_CLICK -->
<div id="disqus-comment">
    <div id="disqus_thread"></div>

<!-- add animation -->
<style>
	.disqus_click_btn {
            line-height: 30px;
            margin: 0;
            min-width: 50px;
            padding: 0 14px;
            display: inline-block;
            font-family: "Roboto", "Helvetica", "Arial", sans-serif;
            font-size: 14px;
            font-weight: 400;
            text-transform: uppercase;
            letter-spacing: 0;
            overflow: hidden;
            will-change: box-shadow;
            transition: box-shadow .2s cubic-bezier(.4, 0, 1, 1), background-color .2s cubic-bezier(.4, 0, .2, 1), color .2s cubic-bezier(.4, 0, .2, 1);
            outline: 0;
            cursor: pointer;
            text-decoration: none;
            text-align: center;
            vertical-align: middle;
            border: 0;
            background: rgba(158, 158, 158, .2);
            box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2), 0 1px 5px 0 rgba(0, 0, 0, .12);
            color: #fff;
            background-color: #7EC0EE;
            text-shadow: 0
        }
</style>
	
<div class="btn_click_load" id="disqus_bt"> 
    <button class="disqus_click_btn">点击查看评论</button>
</div>

<!--
<script type="text/javascript">
$('.btn_click_load').click(function() {
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'http-miccall-tech'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
      dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();

    document.getElementById('disqus_bt').style.display = "none";
});
</script>
-->
<script type="text/javascript">
    var disqus_config = function () {
        this.page.url = 'https://gitee.com/AmeX/amelin-ting.git/2018/05/04/Django------%E8%A7%86%E5%9B%BE%E5%B1%82/';  // Replace PAGE_URL with your page's canonical URL variable
        this.page.identifier = 'https://gitee.com/AmeX/amelin-ting.git/2018/05/04/Django------%E8%A7%86%E5%9B%BE%E5%B1%82/'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
    };
</script>

<script type="text/javascript">
    $('.btn_click_load').click(function() {  //click to load comments
        (function() { // DON'T EDIT BELOW THIS LINE
            var d = document;
            var s = d.createElement('script');
            s.src = '//http-miccall-tech.disqus.com/embed.js';
            s.setAttribute('data-timestamp', + new Date());
            (d.head || d.body).appendChild(s);
        })();
        $('.btn_click_load').css('display','none');
    });
</script>
</div>
<style>
    #disqus-comment{
        background-color: #eee;
        padding: 2pc;
    }
</style>


        </div>
        <!-- Copyright 版权 start -->
                <div id="copyright">
            <ul>
                <li>&copy;Powered By <a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/" style="border-bottom: none;">hexo</a></li>
                <li>Design: <a target="_blank" rel="noopener" href="http://miccall.tech " style="border-bottom: none;">miccall</a></li>
            </ul>
            
                <span id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
			
        </div>
    </div>
</body>



 	
</html>
